package 双指针.移动零;

import java.util.Arrays;

public class MoveZero {
    public static void main(String[] args) {
        Solution so = new Solution();
        int[] arr = {0,1,0,3,12};
        so.moveZeroes(arr);
        System.out.println(Arrays.toString(arr));
    }
}
class Solution {
    public void moveZeroes(int[] nums) {
        for(int cur = 0,dest = -1;cur < nums.length;cur++){
            if(nums[cur] != 0){
                dest++;
                swap(nums,dest,cur);
            }
        }
    }
    public static void swap(int[] nums,int dest,int cur){
        int temp =nums[dest];
        nums[dest] = nums[cur];
        nums[cur] = temp;
    }
}